package org.example.controller;

import org.example.domain.AnswerVO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/topic")
public class TopicServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");//设置response 编码
        AnswerVO answerVO = new AnswerVO();
        answerVO.setDepartment(req.getParameter("department"));
        answerVO.setProfession(req.getParameter("profession"));
        answerVO.setSex(req.getParameter("sex"));
        answerVO.setOne(req.getParameter("one"));
        answerVO.setTwo(req.getParameter("two"));
        answerVO.setThree(req.getParameter("three"));
        answerVO.setFour(req.getParameter("four"));
        String[] fives = req.getParameterValues("five");
        Map<String, String> fivesMap = new HashMap<String, String>();
        for (String five : fives) {
            fivesMap.put(five, five);
        }
        answerVO.setFive(fivesMap);
        answerVO.setSix(req.getParameter("six"));
        req.getSession().setAttribute("answerVO", answerVO);
        System.out.println(answerVO);
        resp.sendRedirect("answer.jsp");
    }
}
